<?php
set_include_path ( get_include_path () . PATH_SEPARATOR . '../' );
include_once 'Include.php';

if(req('user') != ''){
	$userTable = new UserTable();	
	if($_SESSION['vdcode'] != req('validate')){
		echo "validate number error.";
	}else{
		$user = req ('user');
		$email = req ('email');
		$validate = getValidateNum(12,'numberupperlower');
		$data = array("username" => $user, "password" => req ('password'), "email" => $email, 
					  "type"=> 1, "validate" =>$validate , "state" => 0);
		//echo "<pre>". print_r ($data, true) ."</pre>";		
		$exist = $userTable->checkUser($user);
		$existEmail = $userTable->checkEmail($email);
		
		if(!$exist && !$existEmail){		
			$insert_id = $userTable->insert($data);
			$_SESSION['email'] = $email;
		
			// send email
			$href = WWW."web/sign_activate.php?id=".insert_id."&validate=".$validate;
			$to      = $email;
			$subject = 'aba4hire.com Membership Activation';			
			$headers = 'From: danny@simplebyte.net' . "\r\n" .
				'Reply-To: danny@simplebyte.net' . "\r\n" .
				'X-Mailer: PHP/' . phpversion();
			$message = "<p>Congratulations, you got this email.</p>" . 
					"<p>Activate your account by clicking on the activation link below:</p>".
					"<p><a href='" . $href . "'>Activation link here</a></p>".
					"<p>Thanks again for signing up.</p>" .
					"<p>aba4hire.com team</p>".
					"<hr />".
					"<p>If this entry was sent to you without your consent or you have received this email in error, please ignore this email.</p>" . 
					"<p>We love to hear from you. Send us comments / opinions to support@aba4hire.com</p>";
			
			$send = @mail($to, $subject, $message, $headers);			
			header( 'Location: sign_thanks.php' ) ;
		}else{
			echo "the user or email exist. use other please!";
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sign up</title>
<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/G.css" />
<link rel="stylesheet" type="text/css" href="<?=YUI_PATH?>build/fonts/fonts-min.css" />

<script type="text/javascript" src="<?=YUI_PATH?>build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/element/element-min.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/connection/connection-min.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/datatable/datatable-min.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/calendar/calendar-min.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/uploader/uploader.js"></script>
<script type="text/javascript" src="<?=YUI_PATH?>build/resize/resize-min.js"></script>
<script type="text/javascript">

var  Dom = YAHOO.util.Dom,
     Event = YAHOO.util.Event;
	 
</script>

</head>
<body>
<form action="" method="post" onsubmit="return checkForm()">
  <table border="1">
    <caption>
    Just fill in the boxes and get started
    </caption>
    <tr>
      <td>Username:</td>
      <td><input type="text" id="user" name="user" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>your name in aba4hire community</td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" id="password" name="password" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>something you can remember but others can't guess</td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><input type="text" id="email" name="email" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>provide a working email as it will be used to verify your account. ( we hate spam as much as you do )</td>
    </tr>
    <tr>
      <td>A human, right ?</td>
      <td><input type="text" id="validate" name="validate" /> <img id="vd" style=" margin:0 5px; border:#00F solid 1px;" alt="点击切换验证码" onclick="getImgCode()"  /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Not that we don't think you are a human but spammers are getting really smarter these days.</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="checkbox" id="agree" />
        I agree to the terms and conditions</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" value="submit" /></td>
    </tr>
  </table>
</form>
<script type="text/javascript">
function getImgCode(){
	var handleSuccess = function(o){				
		document.getElementById("vd").src = o.responseText;			
	}   
	
	var handleFailure = function(o){  
		if(o.responseText !== undefined){   
			div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";   
			div.innerHTML += "<li>HTTP status: " + o.status + "</li>";   
			div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";   
		}   
	}   
	
	var callback = {   
	  success:handleSuccess,   
	  failure: handleFailure,   
	  argument: { foo:"foo", bar:"bar" }   
	};  
	
	var request = YAHOO.util.Connect.asyncRequest('GET', 'imgCode.php?r='+Math.random(), callback);
}

Event.onDOMReady(function() {	
	getImgCode();
});

function checkForm(){
	var user = $("#user").val();
	var password = $("#password").val();
	var email = $("#email").val();
	var validate = $("#validate").val();
	var agree = $("#agree").attr("checked");
	if(user == "") $("#user").addClass("warn");
	if(password == "") $("#password").addClass("warn");
	if(email == "") $("#email").addClass("warn");
	if(validate == "") $("#validate").addClass("warn");
	if(!agree) $("#agree").addClass("warn");
	if(user && password && email && validate && agree){
		return true;	
	}
	return false;
}

</script>
</body>
</html>